﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// JavaScript 的摘要说明
/// </summary>
public class JavaScript
{
    public JavaScript()
    {

    }
    public static string documentwrite(string str)
    {
        string strScript = "<Script language='javascript'>" +
            "document.write('" + str + "......')" + "</script>";
        return strScript;
    }

    public static string Alert(string str)
    {
        string strScript = "<Script language='javascript'>" +
            "alert('" + str + "......')" + "</script>";
        return strScript;
    }
    public static string Redirct(string url)
    {
        string strScript="<Script language='javascript'>" +
            "self.location ='" +url + "'</script>";
        return strScript;
     //   windown.history.back(-2
    }
    public static string WindowOpen(string url)
    {
        string strScript = "<Script language='javascript'>" +
          " window.open('" + url + "','预览')</script>";
        return strScript;
    }
    public static string HistoryBack()
    {
        string strScript = "<Script language='javascript'>" +
           "window.history.back();</script>";
        return strScript;
    }
    public static string HistoryGo(int n)
    {
        string strScript = "<Script language='javascript'>" +
           "window.history.go("+n+");</script>";
        return strScript;
    }
    public static string CheckString(string str)
    {
        str = str.Replace("'", "");
        str = str.Replace(" ", "");
        str = str.Replace("-", "");
        str = str.Replace(",", "");
      
        str = str.Replace(".", "");
        str = str.Replace(";", "");
      
        return str;
    }
    public static string SimpleCheckString(string str)
    {
        str = str.Replace("'", "");
       
        return str;
    }
    /// <summary>
    /// 控制字符串的长度。
    /// </summary>
    /// <param name="str">源字符串</param>
    /// <param name="n">显示字符个数</param>
    /// <returns></returns>
    public static string StringLength(string str, int n)
    {
        if (n > (str.Length ))
        {
            return str;
        }
        str = str.Substring(0, n );
        return str + "...";
    }
}
